<template>
  <view class="diagnostic-list">
    <view 
      v-for="item in items" 
      :key="item.id" 
      class="diagnostic-item"
      hover-class="item-hover"
      @click="onSelect(item)"
    >
      <view class="item-icon">
        <!-- 修复: 添加默认图标类型，因为items中的icon可能不存在 -->
        <uni-icons :type="item.icon || 'info'" size="24" color="#00ffff"></uni-icons>
		
		<!-- 使用内联样式展示自定义图标 -->
		<!-- <view 
		      class="custom-icon" 
		      :style="{ backgroundImage: `url(${getIconPath(item.icon)})` }"
		    ></view> -->
			
      </view>
      <view class="item-content">
        <text class="item-title">{{ item.title }}</text>
        <text class="item-description">{{ item.description }}</text>
      </view>
      <view class="item-arrow">
        <uni-icons type="right" size="16" color="#ffffff"></uni-icons>
      </view>
    </view>
  </view>
</template>

<script setup>
import { computed } from 'vue';

// // 自定义图标路径映射
// const iconPaths = {
//   'signal': 'path/to/your/signal-icon.png',
//   'download': 'path/to/your/download-icon.png',
//   'error': 'path/to/your/error-icon.png',
//   'location': 'path/to/your/location-icon.png',
//   // 添加一个默认图标路径
//   'default': 'path/to/your/default-icon.png'
// };

// // 获取图标路径的函数
// const getIconPath = (icon) => {
//   return iconPaths[icon] || iconPaths['default'];
// };

// 定义props
const props = defineProps({
  items: {
    type: Array,
    default: () => []
  }
});

// 确保items数组中的每个项目都具有必要的属性
const safeItems = computed(() => {
  return props.items.map(item => ({
    id: item.id || Math.random().toString(36).substr(2, 9),
    title: item.title || '未命名项目',
    description: item.description || '暂无描述',
    icon: item.icon || 'info'
  }));
});

// 定义事件
const emit = defineEmits(['select']);

// 选择项目方法
const onSelect = (item) => {
  emit('select', item);
};
</script>

<style>
.diagnostic-list {
  width: 100%;
  margin-top: 20px;
}

.diagnostic-item {
  display: flex;
  align-items: center;
  padding: 15px;
  background: linear-gradient(90deg, rgba(0, 255, 255, 0.1), transparent);
  border-left: 3px solid #00ffff;
  margin-bottom: 10px;
  border-radius: 0 8px 8px 0;
  position: relative;
  width: 100%;
  box-sizing: border-box;
}

.item-hover {
  background: linear-gradient(90deg, rgba(0, 255, 255, 0.2), rgba(0, 255, 255, 0.05));
  transform: translateX(5px);
}

.item-icon {
  margin-right: 15px;
  min-width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  border: 1px solid rgba(0, 255, 255, 0.5);
  flex-shrink: 0;
}

.item-content {
  flex: 1;
  min-width: 0;
  padding-right: 25px;
}

.item-title {
  font-size: 16px;
  color: #ffffff;
  margin-bottom: 5px;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-description {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-all;
}

.item-arrow {
  position: absolute;
  right: 15px;
  top: 50%;
  transform: translateY(-50%);
  flex-shrink: 0;
}
</style>